<?php
include './include/common.inc.php';
include '../admin/include/att.class.php';
require '../include/form.class.php';
$att = new att_manage();
$action = isset($action) ? $action : 'manage';
$forward = get_forward('/admin/att.php');
switch ($action)
{
	case 'delall':
		if(check_perms('att002')===false)
		{
			$response->alert('您没有此项操作权限！');
			$response->execute();
		}
		if(isset($ck) && sizeof($ck) > 0)
		{
			foreach ($ck as $id)
			{
				$att->delete_att($id);
			}
			$response->alert('删除成功');
			$response->script('self.location=self.location');
		}
		else 
		{
			$response->alert('请选择要删除的附件');
		}
		$response->execute();
		break;
	case 'search':
		$url = $self_url;
		$search_params = array();
		if(isset($name) && !empty($name))
		{
			$search_params[] = 'name='.urlencode($name);
		}
		if(isset($ext) && !empty($ext) && $ext!='0')
		{
			$search_params[] = 'ext='.urlencode($ext);
		}
		if(isset($start) && !empty($start))
		{
			$search_params[] = 'start='.$start;
		}
		if(isset($end) && !empty($end))
		{
			$search_params[] = 'end='.$end;
		}
		if(isset($sizes) && intval($sizes) > 0)
		{
			$search_params[] = 'sizes='.$sizes;
		}
		if(isset($sizee) && intval($sizee) > 0)
		{
			$search_params[] = 'sizee='.$sizee;
		}
		$pos = sizeof($search_params)>0 ? '?' : '';
		$response->redirect($url.$pos.implode('&',$search_params));
		$response->execute();
		break;
	case 'manage':
	default:
		if(check_perms('att001')===false)
		{
			showmessage('您没有此项操作权限！');
		}
		$page = isset($page) ? $page : 1;
		$page = max(1,intval($page));
		$pagesize = 20;
		$params = array('name','ext','start','end','sizes','sizee');
		foreach ($params as $p)
		{
			$$p = isset($$p) ? $$p : '';
		}
		$list = $att->get_atts($page, $pagesize, $name, $ext, $start, $end, $sizes, $sizee);
		$type_list = array_merge(array('0'=>"请选择"), $att->get_file_types());
		$pages = $att->pages;
		$forward = make_forward();
		include template('admin', 'att_manage');
}
?>